//
//  CommentCell.m
//  图你所想
//
//  Created by dllo on 15/8/24.
//  Copyright (c) 2015年 赵璐. All rights reserved.
//

#import "CommentCell.h"


#pragma mark - 话题界面点击全部评论进入的界面的自定义cell

@implementation CommentCell

- (void)awakeFromNib {
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.avatar = [[UIImageView alloc] init];
        [self.contentView addSubview:_avatar];
        [_avatar release];
        
        self.username = [[UILabel alloc] init];
        [self.contentView addSubview:_username];
        [_username release];
        
        self.content = [[UILabel alloc] init];
        [self.contentView addSubview:_content];
        [_content release];
        
        self.date = [[UIButton alloc]init];
        [self.contentView addSubview:self.date];
        [self.date release];
        
        self.floor = [[UILabel alloc]init];
        [self.contentView addSubview:self.floor];
        [self.floor release];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat width = self.contentView.frame.size.width;
    CGFloat offwidth = [UIScreen mainScreen].bounds.size.width / 375;

    CGFloat offheight = [UIScreen mainScreen].bounds.size.height / 667;
    self.avatar.frame = CGRectMake(5, 5, 40 * offheight, 40 * offheight);
    self.avatar.layer.cornerRadius = 20 * offheight;
    self.avatar.layer.masksToBounds = YES;
    
    self.username.frame = CGRectMake(self.avatar.frame.size.width + self.avatar.frame.origin.x + 10, 5, 200 * offwidth , 20 * offheight);
    _username.font = [UIFont systemFontOfSize:13];
    _username.textColor = [UIColor colorWithRed:255/255 green:0 blue:255/255 alpha:0.8];
    
    
    CGFloat h = [[self class] heightWithText:self.content.text];
    self.content.frame = CGRectMake(5, 60, width - 10, (h + 20) * offheight);
    self.content.numberOfLines = 0;
    
    self.date.frame = CGRectMake(self.avatar.frame.size.width + self.avatar.frame.origin.x + 10, 30 * offheight, 80 * offheight , 20 * offheight);
    self.date.titleLabel.font = [UIFont systemFontOfSize:13];
    self.date.titleLabel.textColor = [UIColor lightGrayColor];
    self.floor.frame = CGRectMake(width - 60, 5, 60, 20);
    self.floor.textColor = [UIColor darkGrayColor];
    self.floor.font = [UIFont systemFontOfSize:12];
    
}

+ (CGFloat)heightWithText:(NSString *)text
{
    CGRect rect = [text boundingRectWithSize:CGSizeMake(300 * [[UIScreen mainScreen]bounds].size.width / 375, 0) options:NSStringDrawingUsesLineFragmentOrigin  attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]} context:nil];
    return rect.size.height;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
